package com.ruoyi.cms.controller;

import com.ruoyi.cms.domain.CmsSiteItem;
import com.ruoyi.cms.service.ICmsSiteItemService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 站点栏目Controller
 *
 * @author ruoyi
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/cms/item")
public class CmsSiteItemController extends BaseController
{
    @Autowired
    private ICmsSiteItemService cmsSiteItemService;

    /**
     * 查询站点栏目列表
     */
    @PreAuthorize("@ss.hasPermi('cms:item:list')")
    @GetMapping("/list")
    public AjaxResult list(CmsSiteItem cmsSiteItem)
    {
        List<CmsSiteItem> list = cmsSiteItemService.selectCmsSiteItemList(cmsSiteItem);
        return AjaxResult.success(list);
    }

    /**
     * 导出站点栏目列表
     */
    @PreAuthorize("@ss.hasPermi('cms:item:export')")
    @Log(title = "站点栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsSiteItem cmsSiteItem)
    {
        List<CmsSiteItem> list = cmsSiteItemService.selectCmsSiteItemList(cmsSiteItem);
        ExcelUtil<CmsSiteItem> util = new ExcelUtil<CmsSiteItem>(CmsSiteItem.class);
        util.exportExcel(response, list, "站点栏目数据");
    }

    /**
     * 获取站点栏目详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsSiteItemService.selectCmsSiteItemById(id));
    }

    /**
     * 新增站点栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:item:add')")
    @Log(title = "站点栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsSiteItem cmsSiteItem)
    {
        return toAjax(cmsSiteItemService.insertCmsSiteItem(cmsSiteItem));
    }

    /**
     * 修改站点栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:item:edit')")
    @Log(title = "站点栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsSiteItem cmsSiteItem)
    {
        return toAjax(cmsSiteItemService.updateCmsSiteItem(cmsSiteItem));
    }

    /**
     * 删除站点栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:item:remove')")
    @Log(title = "站点栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsSiteItemService.deleteCmsSiteItemByIds(ids));
    }
}
